<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>fx.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_fx_fx.js.html">fx.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Set of objects that allow animation and visual effects to be
<a name="line17"></a> * easily achieved.
<a name="line18"></a> *
<a name="line19"></a> * (Based loosly on my animation code for 13thparallel.org, with extra
<a name="line20"></a> * inspiration from the DojoToolkit&#39;s modifications to my code)
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.fx&#39;);
<a name="line24"></a>goog.provide(&#39;goog.fx.Animation&#39;);
<a name="line25"></a>goog.provide(&#39;goog.fx.Animation.EventType&#39;);
<a name="line26"></a>goog.provide(&#39;goog.fx.Animation.State&#39;);
<a name="line27"></a>goog.provide(&#39;goog.fx.AnimationEvent&#39;);
<a name="line28"></a>goog.provide(&#39;goog.fx.easing&#39;);
<a name="line29"></a>
<a name="line30"></a>goog.require(&#39;goog.Timer&#39;);
<a name="line31"></a>goog.require(&#39;goog.array&#39;);
<a name="line32"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line33"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line34"></a>goog.require(&#39;goog.object&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>//==============================================================================
<a name="line38"></a>// Constants
<a name="line39"></a>//==============================================================================
<a name="line40"></a>
<a name="line41"></a>
<a name="line42"></a>/**
<a name="line43"></a> * Default timeout for animations (in milliseconds).
<a name="line44"></a> * @type {number}
<a name="line45"></a> */
<a name="line46"></a>goog.fx.TIMEOUT = 20;
<a name="line47"></a>
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>/**
<a name="line51"></a> * Ease in - Start slow and speed up.
<a name="line52"></a> * @param {number} t Input between 0 and 1.
<a name="line53"></a> * @return {number} Output between 0 and 1.
<a name="line54"></a> */
<a name="line55"></a>goog.fx.easing.easeIn = function(t) {
<a name="line56"></a>  return t * t * t;
<a name="line57"></a>};
<a name="line58"></a>
<a name="line59"></a>/**
<a name="line60"></a> * Ease out - Start fastest and slows to a stop.
<a name="line61"></a> * @param {number} t Input between 0 and 1.
<a name="line62"></a> * @return {number} Output between 0 and 1.
<a name="line63"></a> */
<a name="line64"></a>goog.fx.easing.easeOut = function(t) {
<a name="line65"></a>  return 1 - Math.pow(1 - t, 3);
<a name="line66"></a>};
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * Ease in and out - Start slow, speed up, then slow down.
<a name="line71"></a> * @param {number} t Input between 0 and 1.
<a name="line72"></a> * @return {number} Output between 0 and 1.
<a name="line73"></a> */
<a name="line74"></a>goog.fx.easing.inAndOut = function(t) {
<a name="line75"></a>  return 3 * t * t - 2 * t * t * t;
<a name="line76"></a>};
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>
<a name="line80"></a>/**
<a name="line81"></a> * Constructor for an animation object.
<a name="line82"></a> * @param {Array.&lt;number&gt;} start Array for start coordinates.
<a name="line83"></a> * @param {Array.&lt;number&gt;} end Array for end coordinates.
<a name="line84"></a> * @param {number} duration Length of animation in milliseconds.
<a name="line85"></a> * @param {Function} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
<a name="line86"></a> * @constructor
<a name="line87"></a> * @extends {goog.events.EventTarget}
<a name="line88"></a> */
<a name="line89"></a>goog.fx.Animation = function(start, end, duration, opt_acc) {
<a name="line90"></a>  goog.events.EventTarget.call(this);
<a name="line91"></a>
<a name="line92"></a>  if (!goog.isArray(start) || !goog.isArray(end)) {
<a name="line93"></a>    throw Error(&#39;Start and end parameters must be arrays&#39;);
<a name="line94"></a>  }
<a name="line95"></a>
<a name="line96"></a>  if (start.length != end.length) {
<a name="line97"></a>    throw Error(&#39;Start and end points must be the same length&#39;);
<a name="line98"></a>  }
<a name="line99"></a>
<a name="line100"></a>  /**
<a name="line101"></a>   * Start point.
<a name="line102"></a>   * @type {Array.&lt;number&gt;}
<a name="line103"></a>   * @protected
<a name="line104"></a>   */
<a name="line105"></a>  this.startPoint = start;
<a name="line106"></a>
<a name="line107"></a>  /**
<a name="line108"></a>   * End point.
<a name="line109"></a>   * @type {Array.&lt;number&gt;}
<a name="line110"></a>   * @protected
<a name="line111"></a>   */
<a name="line112"></a>  this.endPoint = end;
<a name="line113"></a>
<a name="line114"></a>  /**
<a name="line115"></a>   * Duration of animation in milliseconds.
<a name="line116"></a>   * @type {number}
<a name="line117"></a>   * @protected
<a name="line118"></a>   */
<a name="line119"></a>  this.duration = duration;
<a name="line120"></a>
<a name="line121"></a>  /**
<a name="line122"></a>   * Acceleration function, which must return a number between 0 and 1 for
<a name="line123"></a>   * inputs between 0 and 1.
<a name="line124"></a>   * @type {Function|undefined}
<a name="line125"></a>   * @private
<a name="line126"></a>   */
<a name="line127"></a>  this.accel_ = opt_acc;
<a name="line128"></a>
<a name="line129"></a>  /**
<a name="line130"></a>   * Current coordinate for animation.
<a name="line131"></a>   * @type {Array.&lt;number&gt;}
<a name="line132"></a>   * @protected
<a name="line133"></a>   */
<a name="line134"></a>  this.coords = [];
<a name="line135"></a>};
<a name="line136"></a>goog.inherits(goog.fx.Animation, goog.events.EventTarget);
<a name="line137"></a>
<a name="line138"></a>
<a name="line139"></a>/**
<a name="line140"></a> * Events fired by the animation.
<a name="line141"></a> * @enum {string}
<a name="line142"></a> */
<a name="line143"></a>goog.fx.Animation.EventType = {
<a name="line144"></a>  /**
<a name="line145"></a>   * Dispatched when played for the first time OR when it is resumed.
<a name="line146"></a>   */
<a name="line147"></a>  PLAY: &#39;play&#39;,
<a name="line148"></a>
<a name="line149"></a>  /**
<a name="line150"></a>   * Dispatched only when the animation starts from the beginning.
<a name="line151"></a>   */
<a name="line152"></a>  BEGIN: &#39;begin&#39;,
<a name="line153"></a>
<a name="line154"></a>  /**
<a name="line155"></a>   * Dispatched only when animation is restarted after a pause.
<a name="line156"></a>   */
<a name="line157"></a>  RESUME: &#39;resume&#39;,
<a name="line158"></a>
<a name="line159"></a>  /**
<a name="line160"></a>   * Dispatched when animation comes to the end of its duration OR stop
<a name="line161"></a>   * is called.
<a name="line162"></a>   */
<a name="line163"></a>  END: &#39;end&#39;,
<a name="line164"></a>
<a name="line165"></a>  /**
<a name="line166"></a>   * Dispatched only when stop is called.
<a name="line167"></a>   */
<a name="line168"></a>  STOP: &#39;stop&#39;,
<a name="line169"></a>
<a name="line170"></a>  /**
<a name="line171"></a>   * Dispatched only when animation comes to its end naturally.
<a name="line172"></a>   */
<a name="line173"></a>  FINISH: &#39;finish&#39;,
<a name="line174"></a>
<a name="line175"></a>  /**
<a name="line176"></a>   * Dispatched when an animation is paused.
<a name="line177"></a>   */
<a name="line178"></a>  PAUSE: &#39;pause&#39;,
<a name="line179"></a>
<a name="line180"></a>  /**
<a name="line181"></a>   * Dispatched each frame of the animation.  This is where the actual animator
<a name="line182"></a>   * will listen.
<a name="line183"></a>   */
<a name="line184"></a>  ANIMATE: &#39;animate&#39;,
<a name="line185"></a>
<a name="line186"></a>  /**
<a name="line187"></a>   * Dispatched when the animation is destroyed.
<a name="line188"></a>   */
<a name="line189"></a>  DESTROY: &#39;destroy&#39;
<a name="line190"></a>};
<a name="line191"></a>
<a name="line192"></a>
<a name="line193"></a>/**
<a name="line194"></a> * Enum for the possible states of an animation.
<a name="line195"></a> * @enum {number}
<a name="line196"></a> */
<a name="line197"></a>goog.fx.Animation.State = {
<a name="line198"></a>  STOPPED: 0,
<a name="line199"></a>  PAUSED: -1,
<a name="line200"></a>  PLAYING: 1
<a name="line201"></a>};
<a name="line202"></a>
<a name="line203"></a>
<a name="line204"></a>/**
<a name="line205"></a> * A map of animations which should be cycled on the global timer.
<a name="line206"></a> * @type {Object}
<a name="line207"></a> * @private
<a name="line208"></a> */
<a name="line209"></a>goog.fx.Animation.activeAnimations_ = {};
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * An interval ID for the global timer.
<a name="line214"></a> * @type {number?}
<a name="line215"></a> * @private
<a name="line216"></a> */
<a name="line217"></a>goog.fx.Animation.globalTimer_ = null;
<a name="line218"></a>
<a name="line219"></a>
<a name="line220"></a>/**
<a name="line221"></a> * Cycle all registered animations.
<a name="line222"></a> * @private
<a name="line223"></a> */
<a name="line224"></a>goog.fx.Animation.cycleAnimations_ = function() {
<a name="line225"></a>  goog.Timer.defaultTimerObject.clearTimeout(goog.fx.Animation.globalTimer_);
<a name="line226"></a>
<a name="line227"></a>  // Cycle all animations at the &quot;same time&quot;.
<a name="line228"></a>  var now = goog.now();
<a name="line229"></a>
<a name="line230"></a>  for (var hc in goog.fx.Animation.activeAnimations_) {
<a name="line231"></a>    goog.fx.Animation.activeAnimations_[hc].cycle(now);
<a name="line232"></a>  }
<a name="line233"></a>
<a name="line234"></a>  goog.fx.Animation.globalTimer_ =
<a name="line235"></a>      goog.object.isEmpty(goog.fx.Animation.activeAnimations_) ?
<a name="line236"></a>        null :
<a name="line237"></a>        goog.Timer.defaultTimerObject.setTimeout(
<a name="line238"></a>            goog.fx.Animation.cycleAnimations_, goog.fx.TIMEOUT);
<a name="line239"></a>};
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/**
<a name="line243"></a> * Register an animation to be cycled on the global timer.
<a name="line244"></a> * @param {Object} animation The animation to register.
<a name="line245"></a> */
<a name="line246"></a>goog.fx.Animation.registerAnimation = function(animation) {
<a name="line247"></a>  var hc = goog.getHashCode(animation);
<a name="line248"></a>  if (!(hc in goog.fx.Animation.activeAnimations_)) {
<a name="line249"></a>    goog.fx.Animation.activeAnimations_[hc] = animation;
<a name="line250"></a>  }
<a name="line251"></a>
<a name="line252"></a>  // If the timer is not already started, start it now.
<a name="line253"></a>  if (!goog.fx.Animation.globalTimer_) {
<a name="line254"></a>    goog.fx.Animation.globalTimer_ = goog.Timer.defaultTimerObject.setTimeout(
<a name="line255"></a>        goog.fx.Animation.cycleAnimations_, goog.fx.TIMEOUT);
<a name="line256"></a>  }
<a name="line257"></a>};
<a name="line258"></a>
<a name="line259"></a>
<a name="line260"></a>/**
<a name="line261"></a> * Remove an animation from the list of animations which are cycled on the
<a name="line262"></a> * global timer.
<a name="line263"></a> * @param {Object} animation The animation to unregister.
<a name="line264"></a> */
<a name="line265"></a>goog.fx.Animation.unregisterAnimation = function(animation) {
<a name="line266"></a>  var hc = goog.getHashCode(animation);
<a name="line267"></a>  delete goog.fx.Animation.activeAnimations_[hc];
<a name="line268"></a>
<a name="line269"></a>  // If a timer is running and we no longer have any active timers we stop the
<a name="line270"></a>  // timers.
<a name="line271"></a>  if (goog.fx.Animation.globalTimer_ &amp;&amp;
<a name="line272"></a>      goog.object.isEmpty(goog.fx.Animation.activeAnimations_)) {
<a name="line273"></a>    goog.Timer.defaultTimerObject.clearTimeout(goog.fx.Animation.globalTimer_);
<a name="line274"></a>    goog.fx.Animation.globalTimer_ = null;
<a name="line275"></a>  }
<a name="line276"></a>};
<a name="line277"></a>
<a name="line278"></a>
<a name="line279"></a>/**
<a name="line280"></a> * Current state of the animation.
<a name="line281"></a> * @type {goog.fx.Animation.State}
<a name="line282"></a> * @private
<a name="line283"></a> */
<a name="line284"></a>goog.fx.Animation.prototype.state_ = goog.fx.Animation.State.STOPPED;
<a name="line285"></a>
<a name="line286"></a>
<a name="line287"></a>/**
<a name="line288"></a> * Current frame rate.
<a name="line289"></a> * @type {number}
<a name="line290"></a> * @private
<a name="line291"></a> */
<a name="line292"></a>goog.fx.Animation.prototype.fps_ = 0;
<a name="line293"></a>
<a name="line294"></a>
<a name="line295"></a>/**
<a name="line296"></a> * Percent of the way through the animation.
<a name="line297"></a> * @type {number}
<a name="line298"></a> * @protected
<a name="line299"></a> */
<a name="line300"></a>goog.fx.Animation.prototype.progress = 0;
<a name="line301"></a>
<a name="line302"></a>
<a name="line303"></a>/**
<a name="line304"></a> * Timestamp for when animation was started.
<a name="line305"></a> * @type {number?}
<a name="line306"></a> * @protected
<a name="line307"></a> */
<a name="line308"></a>goog.fx.Animation.prototype.startTime = null;
<a name="line309"></a>
<a name="line310"></a>
<a name="line311"></a>/**
<a name="line312"></a> * Timestamp for when animation was started.
<a name="line313"></a> * @type {number?}
<a name="line314"></a> * @protected
<a name="line315"></a> */
<a name="line316"></a>goog.fx.Animation.prototype.endTime = null;
<a name="line317"></a>
<a name="line318"></a>
<a name="line319"></a>/**
<a name="line320"></a> * Timestamp for when last frame was run.
<a name="line321"></a> * @type {number?}
<a name="line322"></a> * @protected
<a name="line323"></a> */
<a name="line324"></a>goog.fx.Animation.prototype.lastFrame = null;
<a name="line325"></a>
<a name="line326"></a>
<a name="line327"></a>/**
<a name="line328"></a> * Starts or resumes an animation.
<a name="line329"></a> * @param {boolean} opt_restart Whether to restart the
<a name="line330"></a> *     animation from the beginning if it has been paused.
<a name="line331"></a> * @return {boolean} Whether animation was started.
<a name="line332"></a> */
<a name="line333"></a>goog.fx.Animation.prototype.play = function(opt_restart) {
<a name="line334"></a>  if (opt_restart || this.state_ == goog.fx.Animation.State.STOPPED) {
<a name="line335"></a>    this.progress = 0;
<a name="line336"></a>    this.coords = this.startPoint;
<a name="line337"></a>  } else if (this.state_ == goog.fx.Animation.State.PLAYING) {
<a name="line338"></a>    return false;
<a name="line339"></a>  }
<a name="line340"></a>
<a name="line341"></a>  goog.fx.Animation.unregisterAnimation(this);
<a name="line342"></a>
<a name="line343"></a>  this.startTime = /** @type {number} */ (goog.now());
<a name="line344"></a>
<a name="line345"></a>  if (this.state_ == goog.fx.Animation.State.PAUSED) {
<a name="line346"></a>    this.startTime -= this.duration * this.progress;
<a name="line347"></a>  }
<a name="line348"></a>
<a name="line349"></a>  this.endTime = this.startTime + this.duration;
<a name="line350"></a>  this.lastFrame = this.startTime;
<a name="line351"></a>
<a name="line352"></a>  if (!this.progress) {
<a name="line353"></a>    this.onBegin();
<a name="line354"></a>  }
<a name="line355"></a>
<a name="line356"></a>  this.onPlay();
<a name="line357"></a>
<a name="line358"></a>  if (this.state_ == goog.fx.Animation.State.PAUSED) {
<a name="line359"></a>    this.onResume();
<a name="line360"></a>  }
<a name="line361"></a>
<a name="line362"></a>  this.state_ = goog.fx.Animation.State.PLAYING;
<a name="line363"></a>
<a name="line364"></a>  goog.fx.Animation.registerAnimation(this);
<a name="line365"></a>  this.cycle(this.startTime);
<a name="line366"></a>
<a name="line367"></a>  return true;
<a name="line368"></a>};
<a name="line369"></a>
<a name="line370"></a>
<a name="line371"></a>/**
<a name="line372"></a> * Stops the animation.
<a name="line373"></a> * @param {boolean} gotoEnd If true the animation will move to the end coords.
<a name="line374"></a> */
<a name="line375"></a>goog.fx.Animation.prototype.stop = function(gotoEnd) {
<a name="line376"></a>  goog.fx.Animation.unregisterAnimation(this);
<a name="line377"></a>  this.state_ = goog.fx.Animation.State.STOPPED;
<a name="line378"></a>
<a name="line379"></a>  if (gotoEnd) {
<a name="line380"></a>    this.progress = 1;
<a name="line381"></a>  }
<a name="line382"></a>
<a name="line383"></a>  this.updateCoords_(this.progress);
<a name="line384"></a>
<a name="line385"></a>  this.onStop();
<a name="line386"></a>  this.onEnd();
<a name="line387"></a>};
<a name="line388"></a>
<a name="line389"></a>
<a name="line390"></a>/**
<a name="line391"></a> * Pauses the animation (iff it&#39;s playing).
<a name="line392"></a> */
<a name="line393"></a>goog.fx.Animation.prototype.pause = function() {
<a name="line394"></a>  if (this.state_ == goog.fx.Animation.State.PLAYING) {
<a name="line395"></a>    goog.fx.Animation.unregisterAnimation(this);
<a name="line396"></a>    this.state_ = goog.fx.Animation.State.PAUSED;
<a name="line397"></a>    this.onPause();
<a name="line398"></a>  }
<a name="line399"></a>};
<a name="line400"></a>
<a name="line401"></a>
<a name="line402"></a>/**
<a name="line403"></a> * Disposes of the animation.  Stops an animation, fires a &#39;destroy&#39; event and
<a name="line404"></a> * then removes all the event handlers to clean up memory.
<a name="line405"></a> */
<a name="line406"></a>goog.fx.Animation.prototype.disposeInternal = function() {
<a name="line407"></a>  if (this.state_ != goog.fx.Animation.State.STOPPED) {
<a name="line408"></a>    this.stop(false);
<a name="line409"></a>  }
<a name="line410"></a>  this.onDestroy();
<a name="line411"></a>  goog.fx.Animation.superClass_.disposeInternal.call(this);
<a name="line412"></a>};
<a name="line413"></a>
<a name="line414"></a>
<a name="line415"></a>/**
<a name="line416"></a> * Stops an animation, fires a &#39;destroy&#39; event and then removes all the event
<a name="line417"></a> * handlers to clean up memory.
<a name="line418"></a> * @deprecated Use dispose() instead.
<a name="line419"></a> */
<a name="line420"></a>goog.fx.Animation.prototype.destroy = function() {
<a name="line421"></a>  this.dispose();
<a name="line422"></a>};
<a name="line423"></a>
<a name="line424"></a>
<a name="line425"></a>/**
<a name="line426"></a> * Handles the actual iteration of the animation in a timeout
<a name="line427"></a> * @param {number} now The current time.
<a name="line428"></a> */
<a name="line429"></a>goog.fx.Animation.prototype.cycle = function(now) {
<a name="line430"></a>  this.progress = (now - this.startTime) / (this.endTime - this.startTime);
<a name="line431"></a>
<a name="line432"></a>  if (this.progress &gt;= 1) {
<a name="line433"></a>    this.progress = 1;
<a name="line434"></a>  }
<a name="line435"></a>
<a name="line436"></a>  this.fps_ = 1000 / (now - this.lastFrame);
<a name="line437"></a>  this.lastFrame = now;
<a name="line438"></a>
<a name="line439"></a>  if (goog.isFunction(this.accel_)) {
<a name="line440"></a>    this.updateCoords_(this.accel_(this.progress));
<a name="line441"></a>  } else {
<a name="line442"></a>    this.updateCoords_(this.progress);
<a name="line443"></a>  }
<a name="line444"></a>
<a name="line445"></a>  // Animation has finished.
<a name="line446"></a>  if (this.progress == 1) {
<a name="line447"></a>    this.state_ = goog.fx.Animation.State.STOPPED;
<a name="line448"></a>    goog.fx.Animation.unregisterAnimation(this);
<a name="line449"></a>
<a name="line450"></a>    this.onFinish();
<a name="line451"></a>    this.onEnd();
<a name="line452"></a>
<a name="line453"></a>  // Animation is still under way.
<a name="line454"></a>  } else if (this.state_ == goog.fx.Animation.State.PLAYING) {
<a name="line455"></a>    this.onAnimate();
<a name="line456"></a>  }
<a name="line457"></a>};
<a name="line458"></a>
<a name="line459"></a>
<a name="line460"></a>/**
<a name="line461"></a> * Calculates current coordinates, based on the current state.
<a name="line462"></a> * @param {number} t Percentage of the way through the animation as a decimal.
<a name="line463"></a> * @private
<a name="line464"></a> */
<a name="line465"></a>goog.fx.Animation.prototype.updateCoords_ = function(t) {
<a name="line466"></a>  this.coords = new Array(this.startPoint.length);
<a name="line467"></a>  for (var i = 0; i &lt; this.startPoint.length; i++) {
<a name="line468"></a>    this.coords[i] = (this.endPoint[i] - this.startPoint[i]) * t +
<a name="line469"></a>        this.startPoint[i];
<a name="line470"></a>  }
<a name="line471"></a>};
<a name="line472"></a>
<a name="line473"></a>
<a name="line474"></a>/**
<a name="line475"></a> * Dispatches the ANIMATE event. Sub classes should override this instead
<a name="line476"></a> * of listening to the event.
<a name="line477"></a> * @protected
<a name="line478"></a> */
<a name="line479"></a>goog.fx.Animation.prototype.onAnimate = function() {
<a name="line480"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.ANIMATE);
<a name="line481"></a>};
<a name="line482"></a>
<a name="line483"></a>
<a name="line484"></a>
<a name="line485"></a>/**
<a name="line486"></a> * Dispatches the BEGIN event. Sub classes should override this instead
<a name="line487"></a> * of listening to the event.
<a name="line488"></a> * @protected
<a name="line489"></a> */
<a name="line490"></a>goog.fx.Animation.prototype.onBegin = function() {
<a name="line491"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.BEGIN);
<a name="line492"></a>};
<a name="line493"></a>
<a name="line494"></a>
<a name="line495"></a>/**
<a name="line496"></a> * Dispatches the DESTROY event. Sub classes should override this instead
<a name="line497"></a> * of listening to the event.
<a name="line498"></a> * @protected
<a name="line499"></a> */
<a name="line500"></a>goog.fx.Animation.prototype.onDestroy = function() {
<a name="line501"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.DESTROY);
<a name="line502"></a>};
<a name="line503"></a>
<a name="line504"></a>
<a name="line505"></a>/**
<a name="line506"></a> * Dispatches the END event. Sub classes should override this instead
<a name="line507"></a> * of listening to the event.
<a name="line508"></a> * @protected
<a name="line509"></a> */
<a name="line510"></a>goog.fx.Animation.prototype.onEnd = function() {
<a name="line511"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.END);
<a name="line512"></a>};
<a name="line513"></a>
<a name="line514"></a>
<a name="line515"></a>/**
<a name="line516"></a> * Dispatches the FINISH event. Sub classes should override this instead
<a name="line517"></a> * of listening to the event.
<a name="line518"></a> * @protected
<a name="line519"></a> */
<a name="line520"></a>goog.fx.Animation.prototype.onFinish = function() {
<a name="line521"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.FINISH);
<a name="line522"></a>};
<a name="line523"></a>
<a name="line524"></a>
<a name="line525"></a>/**
<a name="line526"></a> * Dispatches the PAUSE event. Sub classes should override this instead
<a name="line527"></a> * of listening to the event.
<a name="line528"></a> * @protected
<a name="line529"></a> */
<a name="line530"></a>goog.fx.Animation.prototype.onPause = function() {
<a name="line531"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.PAUSE);
<a name="line532"></a>};
<a name="line533"></a>
<a name="line534"></a>
<a name="line535"></a>/**
<a name="line536"></a> * Dispatches the PLAY event. Sub classes should override this instead
<a name="line537"></a> * of listening to the event.
<a name="line538"></a> * @protected
<a name="line539"></a> */
<a name="line540"></a>goog.fx.Animation.prototype.onPlay = function() {
<a name="line541"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.PLAY);
<a name="line542"></a>};
<a name="line543"></a>
<a name="line544"></a>/**
<a name="line545"></a> * Dispatches the RESUME event. Sub classes should override this instead
<a name="line546"></a> * of listening to the event.
<a name="line547"></a> * @protected
<a name="line548"></a> */
<a name="line549"></a>goog.fx.Animation.prototype.onResume = function() {
<a name="line550"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.RESUME);
<a name="line551"></a>};
<a name="line552"></a>
<a name="line553"></a>
<a name="line554"></a>/**
<a name="line555"></a> * Dispatches the STOP event. Sub classes should override this instead
<a name="line556"></a> * of listening to the event.
<a name="line557"></a> * @protected
<a name="line558"></a> */
<a name="line559"></a>goog.fx.Animation.prototype.onStop = function() {
<a name="line560"></a>  this.dispatchAnimationEvent_(goog.fx.Animation.EventType.STOP);
<a name="line561"></a>};
<a name="line562"></a>
<a name="line563"></a>
<a name="line564"></a>/**
<a name="line565"></a> * Returns an event object for the current animation.
<a name="line566"></a> * @param {string} type Event type that will be dispatched.
<a name="line567"></a> * @private
<a name="line568"></a> */
<a name="line569"></a>goog.fx.Animation.prototype.dispatchAnimationEvent_ = function(type) {
<a name="line570"></a>  this.dispatchEvent(new goog.fx.AnimationEvent(type, this));
<a name="line571"></a>};
<a name="line572"></a>
<a name="line573"></a>
<a name="line574"></a>
<a name="line575"></a>/**
<a name="line576"></a> * Class for an animation event object.
<a name="line577"></a> * @param {string} type Event type.
<a name="line578"></a> * @param {goog.fx.Animation} anim An animation object.
<a name="line579"></a> * @constructor
<a name="line580"></a> * @extends {goog.events.Event}
<a name="line581"></a> */
<a name="line582"></a>goog.fx.AnimationEvent = function(type, anim) {
<a name="line583"></a>  goog.events.Event.call(this, type);
<a name="line584"></a>
<a name="line585"></a>  /**
<a name="line586"></a>   * The current coordinates.
<a name="line587"></a>   * @type {Array.&lt;number&gt;}
<a name="line588"></a>   */
<a name="line589"></a>  this.coords = anim.coords;
<a name="line590"></a>
<a name="line591"></a>  /**
<a name="line592"></a>   * The x coordinate.
<a name="line593"></a>   * @type {number}
<a name="line594"></a>   */
<a name="line595"></a>  this.x = anim.coords[0];
<a name="line596"></a>
<a name="line597"></a>  /**
<a name="line598"></a>   * The y coordinate.
<a name="line599"></a>   * @type {number}
<a name="line600"></a>   */
<a name="line601"></a>  this.y = anim.coords[1];
<a name="line602"></a>
<a name="line603"></a>  /**
<a name="line604"></a>   * The z coordinate.
<a name="line605"></a>   * @type {number}
<a name="line606"></a>   */
<a name="line607"></a>  this.z = anim.coords[2];
<a name="line608"></a>
<a name="line609"></a>  /**
<a name="line610"></a>   * The current duration.
<a name="line611"></a>   * @type {number}
<a name="line612"></a>   */
<a name="line613"></a>  this.duration = anim.duration;
<a name="line614"></a>
<a name="line615"></a>  /**
<a name="line616"></a>   * The current progress.
<a name="line617"></a>   * @type {number}
<a name="line618"></a>   */
<a name="line619"></a>  this.progress = anim.progress;
<a name="line620"></a>
<a name="line621"></a>  /**
<a name="line622"></a>   * Frames per second so far.
<a name="line623"></a>   */
<a name="line624"></a>  this.fps = anim.fps_;
<a name="line625"></a>
<a name="line626"></a>  /**
<a name="line627"></a>   * The state of the animation.
<a name="line628"></a>   * @type {number}
<a name="line629"></a>   */
<a name="line630"></a>  this.state = anim.state_;
<a name="line631"></a>
<a name="line632"></a>  /**
<a name="line633"></a>   * The animation object.
<a name="line634"></a>   * @type {goog.fx.Animation}
<a name="line635"></a>   */
<a name="line636"></a>  // TODO: This can be removed as this is the same as the target
<a name="line637"></a>  this.anim = anim;
<a name="line638"></a>};
<a name="line639"></a>goog.inherits(goog.fx.AnimationEvent, goog.events.Event);
<a name="line640"></a>
<a name="line641"></a>
<a name="line642"></a>/**
<a name="line643"></a> * Returns the coordinates as integers (rounded to nearest integer).
<a name="line644"></a> * @return {Array.&lt;number&gt;} An array of the coordinates rounded to
<a name="line645"></a> *     the nearest integer.
<a name="line646"></a> */
<a name="line647"></a>goog.fx.AnimationEvent.prototype.coordsAsInts = function() {
<a name="line648"></a>  return goog.array.map(this.coords, Math.round);
<a name="line649"></a>};
</pre>


</body>
</html>
